//
//  HNSH_LocationHelper.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/6.
//

#import "HNSH_LocationHelper.h"

//M
#import <AMapFoundationKit/AMapFoundationKit.h>
#import <AMapLocationKit/AMapLocationKit.h>

@interface HNSH_LocationHelper ()
/** */
@property (nonatomic, strong)AMapLocationManager * manager;
/** */
@property (nonatomic, copy)LocationBlock locationBlock;
@end

@implementation HNSH_LocationHelper

+ (instancetype)share{
    static HNSH_LocationHelper * helper = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate,^{
        helper = [[self alloc] init];
    });
    return helper;
}

- (void)getCurrentLocationWithBlock:(LocationBlock)block{
    self.locationBlock = block;
    [AMapLocationManager updatePrivacyShow:AMapPrivacyShowStatusDidShow privacyInfo:AMapPrivacyInfoStatusDidContain];
    [AMapLocationManager updatePrivacyAgree:AMapPrivacyAgreeStatusDidAgree];
    self.manager = [[AMapLocationManager alloc] init];
    [self.manager setDesiredAccuracy:kCLLocationAccuracyKilometer];
    self.manager.locationTimeout = 5;
    self.manager.reGeocodeTimeout = 5;
    [self.manager requestLocationWithReGeocode:YES completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error) {
        if (regeocode) {
            self.locationBlock(regeocode.formattedAddress, regeocode.district, regeocode.adcode, location.coordinate.longitude, location.coordinate.latitude);
        } else {
            self.locationBlock(nil, nil, nil, 0, 0);
        }
    }];
}

@end
